
package com.wctj.api.infra.common.bean.outbuilder;

import com.wctj.api.infra.common.bean.PayOutMessage;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author egan
 *  <pre>
 *      email egzosn@gmail.com
 *      date 2017/1/13 14:30
 *   </pre>
 */
@Slf4j
public class JsonBuilder  extends BaseBuilder<JsonBuilder, PayOutMessage>{
    JSONObject json = null;

    public JsonBuilder(JSONObject json) {
        this.json = json;
    }

    public JsonBuilder content(String key, Object content) {
        try {
            this.json.putOpt(key, content);
        } catch (JSONException e){
            log.error("org.json.JSONObject 生成JSONObject对象失败", e);
        }
        return this;
    }

    public JSONObject getJson() {
        return json;
    }

    @Override
    public PayOutMessage build() {
        PayJsonOutMessage message = new PayJsonOutMessage();
        setCommon(message);
        message.setContent(json.toString());
        return message;
    }
}
